from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.

class User(AbstractUser):
    # 手机号
    phone = models.CharField(max_length=11,blank=False,unique=True)
    # 头像信息
    avatar = models.ImageField(upload_to='avatar/%Y%m%d/',blank=True)
    # 简介
    desc = models.CharField(max_length=255,blank=True)

    # 视图函数里以手机号为username进行验证
    USERNAME_FIELD = 'phone'

    # 创建超级管理员时需要输入的字段 （不包括手机号和密码）
    REQUIRED_FIELDS = ['username','email']

    class Meta:
        db_table = 'bl_users'
        verbose_name = '用户管理'
        verbose_name_plural = verbose_name # admin后台显示
    
    def __str__(self):
        return self.phone